package com.ruoyi.web.controller.community.electronicCommerce;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.EcRestaurants;
import com.ruoyi.community.service.ec.IEcRestaurantsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区电商Controller
 * 
 * @author ruoyi
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/e-commerce/restaurants")
public class EcRestaurantsController extends BaseController
{
    @Autowired
    private IEcRestaurantsService ecRestaurantsService;

    /**
     * 查询社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:list')")
    @GetMapping("/list")
    public TableDataInfo list(EcRestaurants ecRestaurants)
    {
        startPage();
        List<EcRestaurants> list = ecRestaurantsService.selectEcRestaurantsList(ecRestaurants);
        return getDataTable(list);
    }

    /**
     * 导出社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:export')")
    @Log(title = "社区电商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EcRestaurants ecRestaurants)
    {
        List<EcRestaurants> list = ecRestaurantsService.selectEcRestaurantsList(ecRestaurants);
        ExcelUtil<EcRestaurants> util = new ExcelUtil<EcRestaurants>(EcRestaurants.class);
        return util.exportExcel(list, "社区电商数据");
    }

    /**
     * 获取社区电商详细信息
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:query')")
    @GetMapping(value = "/{restaurantId}")
    public AjaxResult getInfo(@PathVariable("restaurantId") Long restaurantId)
    {
        return AjaxResult.success(ecRestaurantsService.selectEcRestaurantsById(restaurantId));
    }

    /**
     * 新增社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:add')")
    @Log(title = "社区电商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcRestaurants ecRestaurants)
    {
        return toAjax(ecRestaurantsService.insertEcRestaurants(ecRestaurants));
    }

    /**
     * 修改社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:edit')")
    @Log(title = "社区电商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcRestaurants ecRestaurants)
    {
        return toAjax(ecRestaurantsService.updateEcRestaurants(ecRestaurants));
    }

    /**
     * 删除社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:restaurants:remove')")
    @Log(title = "社区电商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{restaurantIds}")
    public AjaxResult remove(@PathVariable Long[] restaurantIds)
    {
        return toAjax(ecRestaurantsService.deleteEcRestaurantsByIds(restaurantIds));
    }
}
